'use strict';

/* Controllers */

angular.module('app.controllers', ['ngCookies'])
  .controller('AppCtrl', ['$scope', '$translate', '$localStorage', '$window',  '$log', '$rootScope', '$state', '$cookies', 'AppConfig', function( $scope, $translate, $localStorage, $window, $log, $rootScope, $state, $cookies, AppConfig ) {
      // add 'ie' classes to html
      var isIE = !!navigator.userAgent.match(/MSIE/i);
      isIE && angular.element($window.document.body).addClass('ie');
      isSmartDevice( $window ) && angular.element($window.document.body).addClass('smart');


      // config
      $scope.app = {
        name: AppConfig.appName,
        version: AppConfig.version,
        // for chart colors
        settings: {
          themeID: 1,
          navbarHeaderColor: 'bg-black',
          navbarCollapseColor: 'bg-white-only',
          asideColor: 'bg-black',
          headerFixed: true,
          asideFixed: false,
          asideFolded: false
        }
      }

      // save settings to local storage
      if ( angular.isDefined($localStorage.settings) ) {
        $scope.app.settings = $localStorage.settings;
      } else {
        $localStorage.settings = $scope.app.settings;
      }
      $scope.$watch('app.settings', function(){ $localStorage.settings = $scope.app.settings; }, true);


      function isSmartDevice( $window )
      {
          // Adapted from http://www.detectmobilebrowsers.com
          var ua = $window['navigator']['userAgent'] || $window['navigator']['vendor'] || $window['opera'];
          // Checks for iOs, Android, Blackberry, Opera Mini, and Windows mobile devices
          return (/iPhone|iPod|iPad|Silk|Android|BlackBerry|Opera Mini|IEMobile/).test(ua);
      };

  }])
.controller( 'PopupController', ['$uibModalInstance', '$scope', 'items', function($uibModalInstance, $scope, items){
  $scope.title = items.title || '消息提示';
  $scope.content = items.content || '';
  $scope.close = function(){
    $uibModalInstance.dismiss();
  }
}]);


  
